package com.ruoyi.common.utils;/*
package com.ruoyi.common.utils;

import com.github.tobato.fastdfs.domain.conn.FdfsWebServer;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.domain.fdfs.ThumbImageConfig;
import com.github.tobato.fastdfs.domain.proto.storage.DownloadByteArray;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.ruoyi.common.utils.bean.FileDTO;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

@Component
public class FastDFSClientUtil {

    @Autowired
    private FastFileStorageClient storageClient;

    @Autowired
    private FdfsWebServer fdfsWebServer;

    @Autowired
    private ThumbImageConfig thumbImageConfig;

    private static FdfsWebServer webServer;

    @PostConstruct
    public void init(){
        webServer = fdfsWebServer;
    }

    //@Autowired
    private SnowFlakeGenerator snowFlakeGenerator;

    */
/**
     * 封装图片完整URL地址
     *//*

    public static String getResAccessUrl(String path) {
        return Optional.ofNullable(path).map(p -> webServer.getWebServerUrl() + p).orElse(null);
    }


    */
/**
     * 封装图片完整URL地址
     *//*

    private String getResAccessUrl(StorePath storePath) {
        return fdfsWebServer.getWebServerUrl() + storePath.getFullPath();
    }
    */
/**
     * 上传文件
     * @param file 文件对象
     * @return 文件访问地址
     *//*

    public String uploadFile(MultipartFile file) throws IOException {
        StorePath storePath = storageClient.uploadFile(
                file.getInputStream(),
                file.getSize(),
                FilenameUtils.getExtension(file.getOriginalFilename()),
                null);
        //return getResAccessUrl(storePath);
        return storePath.getFullPath();
    }

    */
/**
     * 上传文件 通过流
     *//*

    public String uploadFile(InputStream inputStream, long fileSize, String fileExtName) throws IOException {
        StorePath storePath = storageClient.uploadFile(
                inputStream,
                fileSize,
                fileExtName,
                null);
        //return getResAccessUrl(storePath);
        return storePath.getFullPath();
    }

    */
/**
     * 上传文件
     * @param file 文件对象
     * @return 文件访问地址
     *//*

    public String uploadFile(File file) throws IOException {
        StorePath storePath = null;
        try(FileInputStream inputStream = new FileInputStream (file)){
            storePath = storageClient.uploadFile(
                    inputStream,file.length(),
                    FilenameUtils.getExtension(file.getName()),
                    null);
        }
        //return getResAccessUrl(storePath);
        return storePath.getFullPath();
    }

    */
/**
     * 将一段字符串生成一个文件上传
     * @param content 文件内容
     * @param fileExtension 文件扩展名
     *//*

    public String uploadFile(String content, String fileExtension) {
        byte[] buff = content.getBytes(Charset.forName("UTF-8"));
        ByteArrayInputStream stream = new ByteArrayInputStream(buff);
        StorePath storePath = storageClient.uploadFile(stream,buff.length, fileExtension,null);
        return getResAccessUrl(storePath);
    }

    */
/**
     * 上传图片并且生成缩略图
     * @param file 文件对象
     * @return 文件访问地址
     *//*

    public String uploadImage(MultipartFile file) throws IOException {
        StorePath storePath = storageClient.uploadImageAndCrtThumbImage(
                file.getInputStream(),
                file.getSize(),
                FilenameUtils.getExtension(file.getOriginalFilename()),
                null);
        // 带分组的路径
        System.out.println(storePath.getFullPath());
        // 不带分组的路径
        System.out.println(storePath.getPath());
        // 获取缩略图路径
        String path = thumbImageConfig.getThumbImagePath(storePath.getPath());
        System.out.println(path);
        return getResAccessUrl(storePath);
    }
    */
/**
     * 删除文件
     * @param fileUrl 文件访问地址
     *//*

    public void deleteFile(String fileUrl) {
        StorePath storePath = StorePath.parseFromUrl(fileUrl);
        storageClient.deleteFile(storePath.getGroup(), storePath.getPath());
    }

    */
/**
     * 下载文件
     *//*

    public byte[] downloadFile(String fileUrl)  {
        StorePath storePath = StorePath.parseFromUrl(fileUrl);
        DownloadByteArray downloadByteArray = new DownloadByteArray();
        byte[] bytes = this.storageClient.downloadFile(storePath.getGroup(), storePath.getPath(), downloadByteArray);
        //将文件保存到本地磁盘
        try (
                FileOutputStream fileOutputStream = new FileOutputStream("C:/Users/86186/Desktop/911565.jpg");
            ){
            fileOutputStream.write(bytes);
        }catch (Exception e){
              e.printStackTrace();
        }
        return bytes;
    }


    */
/**
     *  上传多文件
     *//*

    public List<FileDTO> uploadMultipleFiles(HttpServletRequest request) throws IOException {
        List<FileDTO> paths = new ArrayList<>();
        // 创建一个通用的多部分解析器
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getServletContext());
        // 判断 request 是否有文件上传,即多部分请求 。检查form中是否有enctype="multipart/form-data"
        if (multipartResolver.isMultipart(request)) {
            // 转换成多部分request
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
            // 取得request中的所有文件名
            Iterator<String> iter = multiRequest.getFileNames();
            while (iter.hasNext()) {
                final String fileKey = iter.next();
                //file1-10
                final String[] fileKeys = fileKey.split("-");
                final String time = fileKeys[1];
                // 取得上传文件
                MultipartFile file = multiRequest.getFile(fileKey);
                final String path = this.uploadFile(file);
                paths.add(FileDTO.builder().path(path).time(time).build());
            }
        }
        return paths;
    }

    */
/**
     * 上传成压缩包
     *//*

    */
/*public String zip(List<String> urls) throws Exception{
        File parent = new File( CommonProperties.getStaticTmp() + snowFlakeGenerator.nextId() + "/");
        File zipFile = new File(parent, snowFlakeGenerator.nextId() + ".zip");
        List<File> files = Lists.newArrayList();
        for (String url : urls ) {
            String name = FilenameUtils.getName(url);
            File file = new File(parent, name);
            FileUtils.copyURLToFile(new URL(url),file);
            files.add(file);
        }
        ZipUtil.zip(zipFile , false, files.toArray(new File[0]));
        String path = this.uploadFile(zipFile);
        if(parent.exists()){
            FileUtils.deleteQuietly(parent);
        }
        return path;
    }*//*


}*/
